package day08.synch;

import day08.synch.thread.ThreadA;
import day08.synch.thread.ThreadB;
import day08.synch.thread.ThreadC;
import org.junit.Test;

/**
 * @Auther: sky
 * @Date: 2019/3/4 22:56
 * @Description:
 */
public class Run {

    public static void main(String[] args) {

        //多个线程多个锁，以异步的方式执行，synchronized锁的是对象，而不是锁的方法
        SyncTest syncTest1 = new SyncTest();
        SyncTest syncTest2 = new SyncTest();

        ThreadA thread = new ThreadA(syncTest1);
        thread.start();

        ThreadB thread1 = new ThreadB(syncTest2);
        thread1.start();
    }


    @Test
    public void dirtyRead() {
        try {
            DirtyReading dirtyReading = new DirtyReading();
            ThreadC threadC = new ThreadC(dirtyReading);
            threadC.start();
            Thread.sleep(5000);
            dirtyReading.getValue();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
